package com.bing.controller.util;

import com.bing.entity.Weather;
import com.bing.services.JSService;
import com.bing.services.UtilService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by kaibb on 16-1-3.
 */
@Controller
@RequestMapping(UtilController.PRE)
public class UtilController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UtilController.class);
    protected static final String PRE = "util";
    @Autowired
    private JSService jsService;

    @Autowired
    private UtilService utilService;


    @RequestMapping(value = "weather", produces = {MediaType.APPLICATION_JSON_VALUE})
    @ResponseBody
    private Weather getWeather(@RequestParam("longitude") double longitude, @RequestParam("latitude") double latitude) {
        LOGGER.info("获取天气情况:{},{}", longitude, latitude);
        Weather weather = jsService.getWeather(longitude, latitude);
        return weather;
    }

    @RequestMapping("backUp")
    @ResponseBody
    private Boolean backUp() {
        return utilService.backUpDB();
    }

    @RequestMapping("restore/{date}")
    @ResponseBody
    private Boolean restore(@PathVariable String date) {
        return utilService.restoreDB(date);
    }


}
